import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class Client implements Runnable {
	private static Socket socket;
	
	private static Scanner scanner;
	
	private static String username;
	private static String userpassword;
	
	public static void main(String[] args) {
		try {
			socket = new Socket("localhost", 1010);
			
			scanner = new Scanner(System.in);
			
			System.out.println("Please input user name:");
			username = scanner.nextLine();
			
			System.out.println("Please input user password:");
			userpassword = scanner.next();
			
			PrintWriter pw = new PrintWriter(socket.getOutputStream());
			
			pw.println(username + ":" + userpassword);
			pw.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}
		
		new Thread(new Client()).start();
	}

	@Override
	public void run() {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			
			String content;
			
			while ((content = br.readLine()) != null) {
				System.out.println(content);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}






















